clear
set more off

local ylist -80 -60 -40 -20 0 25 100
local wc = wordcount("`ylist'")



cap file close myfile
file open myfile using "$outdir/tables/delta_gr.tex", write replace

file write myfile "	&	\multicolumn{2}{c}{2020Q2-2020Q4} "
file write myfile "	&	\multicolumn{2}{c}{2021Q1-2021Q3} "
file write myfile "	\\ "
file write myfile "	\cline{2-3} \cline{4-5} "

file write myfile " & ERC & Wages & ERC & Wages \\ "
file write myfile " Rel. change in GR: & (1) & (2) & (3) & (4) \\ "
file write myfile "\midrule" _n





forval i = 0/`=`wc'' {
	
	// write the header
	if `i' == 0 {
		file write myfile " Less than -80\% "
	}
	else if `i' == `wc' {
		file write myfile " Greater than 100\% "
	}
	
	else if `i' >= 1 {
		local y0 : word `i' of `ylist'
		local y1 : word `=`i'+1' of `ylist'
		
		local y0_format : di %10.0fc `=`y0'*1000'
		local y1_format : di %10.0fc `=`y1'*1000'
		
		file write myfile " `y0'\% to `y1'\% "
	}
	
	// write the rows
	forval post = 0/1 {
		use "$statadir/delta_gr" if post == `post' & bin == `i', clear

		local ertc : di %6.3f share_ertc[1]
		local wg : di %6.3f share_wg_amt[1]
		
		file write myfile " & `ertc' & `wg' "

	}
	file write myfile " \\ "
	
	if `i' < `wc' {
		file write myfile " \addlinespace[6pt] "
	}
		

}

cap file close myfile



